﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace KursachApp
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class NotesPage : ContentPage
    {
        public int usid;

        public NotesPage(int userid)
        {
            InitializeComponent();
             usid = userid;

        }

        protected override async void OnAppearing()
        {
            //int usid = 
            // создание таблицы, если ее нет
            await App.Database.CreateTable2();
            // привязка данных
            notesList.ItemsSource = await App.Database.GetItemsAsync2(usid);

            base.OnAppearing();
        }


        private async void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            Notes selectedNote = (Notes)e.SelectedItem;
            CRUDNotesPage notePage = new CRUDNotesPage(usid);
            notePage.BindingContext = selectedNote;
            await Navigation.PushAsync(notePage);
        }

        private async void CreateNotes(object sender, EventArgs e)
        {
            Notes note = new Notes();
            CRUDNotesPage notePage = new CRUDNotesPage(usid);
            notePage.BindingContext = note;
            await Navigation.PushAsync(notePage);
        }
    }
}